﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Windows.Forms;
using AmiEmuLib;
using AmiEmuLib.Configuration;
using AmiEmuLib.Configuration.DefaultAmigaConfigsConfig;
using AmiEmuLib.Configuration.EventBindingConfig;
using AmiEmuLib.Configuration.FloppySoundConfig;
using AmiEmuLib.Configuration.KnownRomConfig;
using AmiEmuLib.Host;
using AmiEmuLib.Host.HostInput;
using AmiEmuLib.Native;
using AmiEmuLib.AmigaConfiguration;
using System.Globalization;
using TomanuExtensions;
using TomanuExtensions.Utils;
using AmiEmuLib.Configuration.AmigaAudioConfig;

namespace AmiEmu
{
    public partial class AmiEmuForm : HostWindow
    {
        private SoundPlayer m_player = new SoundPlayer();

        private int m_win_mouse_x;
        private int m_win_mouse_y;
        private bool m_win_mouse_left_btn;
        private bool m_win_mouse_right_btn;
        private bool m_win_mouse_middle_btn;
        private int m_win_mouse_wheel;
        private int m_win_mouse_horz_wheel;

        private int m_raw_mouse_x;
        private int m_raw_mouse_y;
        private bool m_raw_mouse_left_btn;
        private bool m_raw_mouse_right_btn;
        private bool m_raw_mouse_middle_btn;
        private int m_raw_mouse_wheel;
        private int m_raw_mouse_horz_wheel;

        public AmiEmuForm()
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo("loggers.config.xml"));
            InitializeComponent();
        }

        private void buttonSaveEditedRoms_Click(object sender, EventArgs e)
        {
            KnownRoms.SaveToXml();
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == (Keys.Alt | Keys.F4))
                return true;
            else if (keyData == (Keys.Control | Keys.Cancel))
                return true;
            else
                return base.ProcessDialogKey(keyData);
        }

        private void AmiEmuForm_Load(object sender, EventArgs e)
        {
            HostEnvironment.AttachToHostWindow(this);

            romInfosDataGridView.DataSource = new SortableBindingList<KnownRom>(
                KnownRoms.Roms.OrderBy(k => k.RomTypes).ToList());

            var newcol = new DataGridViewComboBoxColumn();
            newcol.DataPropertyName = "HardwareType";
            newcol.DataSource = EnumExtensions.GetValues<HardwareType>();
            newcol.Name = "HardwareType";
            newcol.FlatStyle = FlatStyle.Flat;

            romInfosDataGridView.Columns.Remove(romInfosDataGridView.Columns[4]);
            romInfosDataGridView.Columns.Insert(4, newcol);

            romsDirectoryTextBox.Text = Config.Instance.RomsDirectory;

            floppySoundsListBox.DataSource = FloppySoundsList.List.ToList();

            tabConstrols.SelectedIndex = 6;

            MouseHandlers();

            foreach (var ev in HostEventsList.KeyboardEvents.Events)
                HostInputDevicesList.RegisterEvent(ev, KeyInput);

            eventBindingsDataGridView.AutoGenerateColumns = false;

            UpdateBindingEventsList(null);

            try
            {
                AmiEmuLib.AmigaConfiguration.ChipsetConfig.ChipsetType ch1;
                AmiEmuLib.AmigaConfiguration.ChipsetConfig.ChipsetType ch2;
                ch1 = AmiEmuLib.AmigaConfiguration.ChipsetConfig.ChipsetType.AGA;
                ch2 = AmiEmuLib.AmigaConfiguration.ChipsetConfig.ChipsetType.ECS_Denise |
                    AmiEmuLib.AmigaConfiguration.ChipsetConfig.ChipsetType.ECS_Agnus;
                bool b1 = Enum.IsDefined(typeof(AmiEmuLib.AmigaConfiguration.ChipsetConfig.ChipsetType), ch1);
                bool b2 = Enum.IsDefined(typeof(AmiEmuLib.AmigaConfiguration.ChipsetConfig.ChipsetType), ch2);
                b1.ToString();
                //DefaultAmigaConfigs.SaveToXml();
                //DefaultEventsBindings.SaveToXml();
            }
            catch (Exception ex)
            {
                Debugger.Break();
                ex.ToString();
            }
        }

        private void UpdateBindingEventsList(EventsBinding a_select = null)
        {
            eventBindingsComboBox.DataSource =
                EventsBindingList.List.Select(
                    evs => new EventsBindingItem() { EventsBinding = evs }).ToList();

            List<EventsBindingItem> list = eventBindingsComboBox.DataSource as List<EventsBindingItem>;

            if (a_select != null)
                eventBindingsComboBox.SelectedItem = list.FirstOrDefault(
                    s => s.EventsBinding == a_select);
        }

        private void romsDirectoryButton_Click(object sender, EventArgs e)
        {
            romsDirectoryFolderBrowserDialog.SelectedPath =
                new DirectoryInfo(Config.Instance.RomsDirectory).FindExistingDirectory();

            try
            {
                if (FileUtils.IsFilePathValid(romsDirectoryButton.Text))
                    romsDirectoryFolderBrowserDialog.SelectedPath =
                        new DirectoryInfo(romsDirectoryTextBox.Text).FindExistingDirectory();
            }
            catch
            {
            }

            if (romsDirectoryFolderBrowserDialog.ShowDialog() == DialogResult.OK)
                romsDirectoryTextBox.Text = romsDirectoryFolderBrowserDialog.SelectedPath;
        }

        private void rescanButton_Click(object sender, EventArgs e)
        {
            List<List<string>> duplicates = new List<List<string>>();

            KnownRoms.Rescan(duplicates);

            if (duplicates.Count() > 0)
            {
                String str1 = "Duplicates was found:" + System.Environment.NewLine;

                foreach (var dup in duplicates)
                {
                    str1 += System.Environment.NewLine;

                    foreach (var d in dup)
                        str1 += d + System.Environment.NewLine;
                }

                MessageBox.Show(str1, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (UnknownRoms.Roms.Count() > 0)
            {
                String str2 = String.Format("Unknown roms ({0}):", UnknownRoms.Roms.Count()) + System.Environment.NewLine;

                foreach (var unknown in UnknownRoms.Roms)
                    str2 += System.Environment.NewLine + unknown.FilePath;

                MessageBox.Show(str2, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            String str3 = "Available Amiga Models:" + System.Environment.NewLine + System.Environment.NewLine;

            var def_configs = from def_config in DefaultAmigaConfigs.Configs
                              group def_config by def_config.ShortDescription into g
                              select g.First();

            foreach (var def_config in def_configs)
            {
                str3 += def_config.ShortDescription + ": ";

                if (def_config.RomsAvailable())
                    str3 += "available";
                else
                    str3 += "unavailable";

                str3 += System.Environment.NewLine;
            }

            MessageBox.Show(str3, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void romsDirectoryTextBox_TextChanged(object sender, EventArgs e)
        {
            if (FileUtils.IsFilePathValid(romsDirectoryTextBox.Text))
                Config.Instance.RomsDirectory = romsDirectoryTextBox.Text;
        }

        private void floppySoundsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            FloppySounds fs = (FloppySounds)floppySoundsListBox.SelectedItem;
            floppySoundListBox.DataSource = fs.Sounds.ToList();
        }

        private void AmiEmuForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            m_player.Stop();
        }

        private void buttonPlay_Click(object sender, EventArgs e)
        {
            FloppySound fs = (FloppySound)floppySoundListBox.SelectedItem;

            m_player.Stream = fs.GetStream();
            m_player.Play();
        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            m_player.Stop();
        }

        private void buttonMouseReset_Click(object sender, EventArgs e)
        {
            m_win_mouse_x = 0;
            m_win_mouse_y = 0;
            m_win_mouse_left_btn = false;
            m_win_mouse_right_btn = false;
            m_win_mouse_middle_btn = false;
            m_win_mouse_wheel = 0;
            m_win_mouse_horz_wheel = 0;

            m_raw_mouse_x = 0;
            m_raw_mouse_y = 0;
            m_raw_mouse_left_btn = false;
            m_raw_mouse_right_btn = false;
            m_raw_mouse_middle_btn = false;
            m_raw_mouse_wheel = 0;
            m_raw_mouse_horz_wheel = 0;

            UpdateMouseRichEdit();
        }

        private void MouseHandlers()
        {
            // Displays information about the system mouse.
            richTextBoxMouseLog.AppendText(
                "\nSystemInformation.MousePresent: " + SystemInformation.MousePresent.ToString());
            richTextBoxMouseLog.AppendText(
                "\nSystemInformation.MouseButtons: " + SystemInformation.MouseButtons.ToString());
            richTextBoxMouseLog.AppendText(
                "\nSystemInformation.MouseButtonsSwapped: " +
                SystemInformation.MouseButtonsSwapped.ToString());
            richTextBoxMouseLog.AppendText(
                "\nSystemInformation.MouseWheelPresent: " + SystemInformation.MouseWheelPresent.ToString());
            richTextBoxMouseLog.AppendText(
                "\nSystemInformation.MouseWheelScrollLines: " +
                SystemInformation.MouseWheelScrollLines.ToString());
            richTextBoxMouseLog.AppendText(
                "\nSystemInformation.NativeMouseWheelSupport: " +
                SystemInformation.NativeMouseWheelSupport.ToString());
            richTextBoxMouseLog.AppendText("\n");

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Move_Absolute_X), (ev, state, value) =>
                {
                    m_raw_mouse_x = value;
                    richTextBoxMouseLog.AppendText("Absolute mouse\n");
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Move_Absolute_Y), (ev, state, value) =>
                {
                    m_raw_mouse_y = value;
                    richTextBoxMouseLog.AppendText("Absolute mouse\n");
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Move_Relative_X), (ev, state, value) =>
                {
                    m_raw_mouse_x += value;
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Move_Relative_Y), (ev, state, value) =>
                {
                    m_raw_mouse_y += value;
                    UpdateMouseRichEdit();
                });

            HostEnvironment.DeviceChanged += () =>
            {
                richTextBoxMouseLog.AppendText("Device changed\n");
                UpdateMouseRichEdit();
            };

            for (int i = HostMiceDevices.Event_ID_Extra_Button_4; i <= HostMiceDevices.Event_ID_Extra_Button_32; i++)
            {
                HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(i),
                    (ev, state, value) =>
                    {
                        richTextBoxMouseLog.AppendText(
                    String.Format("Custom button, index: {0}, state: {1}\n", value, state));
                        UpdateMouseRichEdit();
                        UpdateMouseRichEdit();
                    });
            }

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Horizontal_Wheel_Left), (ev, state, value) =>
                {
                    m_raw_mouse_horz_wheel += value;
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Horizontal_Wheel_Right), (ev, state, value) =>
                {
                    m_raw_mouse_horz_wheel += value;
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Wheel_Down), (ev, state, value) =>
                {
                    m_raw_mouse_wheel += value;
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Wheel_Up), (ev, state, value) =>
                {
                    m_raw_mouse_wheel += value;
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Left_Button), (ev, state, value) =>
                {
                    m_raw_mouse_left_btn = state;
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Right_Button), (ev, state, value) =>
                {
                    m_raw_mouse_right_btn = state;
                    UpdateMouseRichEdit();
                });

            HostInputDevicesList.RegisterEvent(HostEventsList.MouseEvents.GetEvent(
                HostMiceDevices.Event_ID_Middle_Button), (ev, state, value) =>
                {
                    m_raw_mouse_middle_btn = state;
                    UpdateMouseRichEdit();
                });
        }

        private void UpdateMouseRichEdit()
        {
            richTextBoxMouse.Clear();

            richTextBoxMouse.AppendText(String.Format("WinMouse:\n\n"));
            richTextBoxMouse.AppendText(String.Format("X: {0}, Y: {1}\n",
                m_win_mouse_x, m_win_mouse_y));
            richTextBoxMouse.AppendText(String.Format("Wheel: {0}, HorsWheel: {1}\n",
                m_win_mouse_wheel, m_win_mouse_horz_wheel));
            richTextBoxMouse.AppendText(String.Format("Left: {0}, Middle: {1}, Right: {2}\n\n",
                m_win_mouse_left_btn, m_win_mouse_middle_btn, m_win_mouse_right_btn));

            richTextBoxMouse.AppendText(String.Format("RawMouse:\n\n"));
            richTextBoxMouse.AppendText(String.Format("X: {0}, Y: {1}\n",
                m_raw_mouse_x, m_raw_mouse_y));
            richTextBoxMouse.AppendText(String.Format("Wheel: {0}, HorsWheel: {1}\n",
                m_raw_mouse_wheel, m_raw_mouse_horz_wheel));
            richTextBoxMouse.AppendText(String.Format("Left: {0}, Middle: {1}, Right: {2}\n\n",
                m_raw_mouse_left_btn, m_raw_mouse_middle_btn, m_raw_mouse_right_btn));
        }

        private void richTextBoxMouse_MouseMove(object sender, MouseEventArgs e)
        {
            m_win_mouse_x = e.X;
            m_win_mouse_y = e.Y;

            m_win_mouse_left_btn = e.Button.HasFlag(MouseButtons.Left);
            m_win_mouse_middle_btn = e.Button.HasFlag(MouseButtons.Middle);
            m_win_mouse_right_btn = e.Button.HasFlag(MouseButtons.Right);

            if (e.Button.HasFlag(MouseButtons.XButton1))
                richTextBoxMouseLog.AppendText("Button 4 clicked\n");
            if (e.Button.HasFlag(MouseButtons.XButton2))
                richTextBoxMouseLog.AppendText("Button 5 clicked\n");

            m_win_mouse_wheel += e.Delta;

            UpdateMouseRichEdit();
        }

        private void richTextBoxMouse_MouseDown(object sender, MouseEventArgs e)
        {
            m_win_mouse_left_btn = e.Button.HasFlag(MouseButtons.Left);
            m_win_mouse_middle_btn = e.Button.HasFlag(MouseButtons.Middle);
            m_win_mouse_right_btn = e.Button.HasFlag(MouseButtons.Right);

            if (e.Button.HasFlag(MouseButtons.XButton1))
                richTextBoxMouseLog.AppendText("Button 4 clicked\n");
            if (e.Button.HasFlag(MouseButtons.XButton2))
                richTextBoxMouseLog.AppendText("Button 5 clicked\n");

            m_win_mouse_wheel += e.Delta;

            UpdateMouseRichEdit();
        }

        private void richTextBoxMouse_MouseUp(object sender, MouseEventArgs e)
        {
            m_win_mouse_left_btn = e.Button.HasFlag(MouseButtons.Left);
            m_win_mouse_middle_btn = e.Button.HasFlag(MouseButtons.Middle);
            m_win_mouse_right_btn = e.Button.HasFlag(MouseButtons.Right);

            if (e.Button.HasFlag(MouseButtons.XButton1))
                richTextBoxMouseLog.AppendText("Button 4 clicked\n");
            if (e.Button.HasFlag(MouseButtons.XButton2))
                richTextBoxMouseLog.AppendText("Button 5 clicked\n");

            m_win_mouse_wheel += e.Delta;

            UpdateMouseRichEdit();
        }

        private void KeyInput(HostEvent a_event, bool a_pressed, int a_key)
        {
            if (((int)a_key < 255) && (a_key > 0))
            {
                string name1 = HostEventsList.KeyboardEvents.Events.ElementAt((int)a_key - 1).Name;
                string name2 = HostEventsList.KeyboardEvents.Events.ElementAt((int)a_key - 1).DisplayName;

                keyboardRichTextBox.AppendText(String.Format("RawInput: {0:X}, {1}, {2}, {3}\n",
                    a_key, a_pressed, name1, name2));
            }
            else
            {
                keyboardRichTextBox.AppendText(String.Format("RawInput: {0:X}, {1} \n",
                    a_key, a_pressed));
            }

            keyboardRichTextBox.ScrollToEnd();
        }

        private void keyboardRichTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            keyboardRichTextBox.AppendText(String.Format(
                "KeyDown: alt: {0}, ctrl: {1}, keycode: {2:X}, keydata: {3:X}, keyvalue: {4:X}, modifiers: {5:X}, shift: {6}\n",
                e.Alt, e.Control, e.KeyCode, e.KeyData, e.KeyValue, e.Modifiers, e.Shift));

            keyboardRichTextBox.ScrollToEnd();
        }

        private void keyboardRichTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            char x = '\0';
            for (uint i = 0; i < 255; i++)
            {
                x = (char)NativeRawInput.MapVirtualKey(i,
                    NativeRawInput.MapVirtualKeyEnum.MAPVK_VK_TO_CHAR);
                if (x == e.KeyChar)
                    break;
            }

            keyboardRichTextBox.AppendText(String.Format(
                "KeyPress: char: {0} ({1:X4}, keycode: {1:X4})\n",
                    e.KeyChar, (int)e.KeyChar, (ushort)x));

            keyboardRichTextBox.ScrollToEnd();
        }

        private void keyboardRichTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            keyboardRichTextBox.AppendText(String.Format(
                "KeyUp: alt: {0}, ctrl: {1}, keycode: {2:X}, keydata: {3:X}, keyvalue: {4:X}, modifiers: {5:X}, shift: {6}\n",
                e.Alt, e.Control, e.KeyCode, e.KeyData, e.KeyValue, e.Modifiers, e.Shift));

            keyboardRichTextBox.ScrollToEnd();
        }

        private void bindingsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateEventBindingsGrid();
        }

        private void UpdateEventBindingsGrid()
        {
            EventsBinding bindings =
                (eventBindingsComboBox.SelectedItem as EventsBindingItem).EventsBinding;

            var data = from binding in bindings.Bindings
                       select new EventBindingRow() { EventBinding = binding };

            if (hideFromMappingCheckBox.Checked)
                data = data.Where(ev => !ev.EventBinding.AmigaEvent.HideFromMapping);

            eventBindingsDataGridView.DataSource = data.ToList();

            var ds = HostEventsList.All.Select(ev => ev.Name).OrderBy(s => s).ToList();
            ds.Insert(0, "");

            renameEventBindingsButton.Enabled = !bindings.ReadOnly;
            deleteEventBindingsButton.Enabled = !bindings.ReadOnly;
        }

        private void bindingsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            ShowMappingForm();
        }

        private void bindingsDataGridView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                ShowMappingForm();
        }

        private void ShowMappingForm()
        {
            var x = (EventBindingRow)eventBindingsDataGridView.Rows[
                eventBindingsDataGridView.SelectedCells[0].RowIndex].DataBoundItem;

            if (x.EventBinding.ReadOnly)
                return;

            EventsMappingForm form = new EventsMappingForm(x.EventBinding,
                eventBindingsDataGridView.SelectedCells[0].ColumnIndex - 1);

            var cell_rect = eventBindingsDataGridView.GetCellDisplayRectangle(eventBindingsDataGridView.SelectedCells[0].ColumnIndex,
                eventBindingsDataGridView.SelectedCells[0].RowIndex, false);

            var rect = form.Bounds;

            rect.Location = new Point(
                cell_rect.Left + (cell_rect.Width - rect.Width) / 2,
                cell_rect.Top + (cell_rect.Height - rect.Height) / 2);

            var area = Screen.FromHandle(Handle).WorkingArea;
            rect = eventBindingsDataGridView.RectangleToScreen(rect);

            if (rect.Left < area.Left)
                rect.Offset(area.Left - rect.Left, 0);
            if (rect.Top < area.Top)
                rect.Offset(0, area.Top - rect.Top);
            if (rect.Right > area.Right)
                rect.Offset(area.Right - rect.Right, 0);
            if (rect.Bottom > area.Bottom)
                rect.Offset(0, area.Bottom - rect.Bottom);

            form.Location = rect.Location;

            form.ShowDialog();
        }

        private void hideFromMappingCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            UpdateEventBindingsGrid();
        }

        private void renameEventBindingsButton_Click(object sender, EventArgs e)
        {
            EventsBinding bindings =
                (eventBindingsComboBox.SelectedItem as EventsBindingItem).EventsBinding;

            var names = eventBindingsComboBox.Items.Cast<EventsBindingItem>().Select(
                b => b.EventsBinding.Name).ToList();

            InputForm.Create("Rename bindings:", "New bindings name:",
                (result) =>
                {
                    if (bindings.Name != result)
                    {
                        bindings.Name = result;
                        UpdateBindingEventsList(bindings);
                    }
                },
                bindings.Name, (val) =>
                {
                    val = val.Trim();

                    if (val == "")
                        return "Name cannot be empty";
                    else if (names.Except(bindings.Name).Any(n => n == val))
                    {
                        return "Bindings with this name already exists";
                    }
                    else
                        return null;
                });
        }

        private void newEventBindingsButton_Click(object sender, EventArgs e)
        {
            EventsBinding bindings =
                (eventBindingsComboBox.SelectedItem as EventsBindingItem).EventsBinding;

            var names = eventBindingsComboBox.Items.Cast<EventsBindingItem>().Select(
                    b => b.EventsBinding.Name).Concat(
                        eventBindingsComboBox.Items.Cast<EventsBindingItem>().Select(
                            b => b.EventsBinding.Name)).Distinct().ToList();

            InputForm.Create("New bindings:", "New bindings name:",
                (result) =>
                {
                    UpdateBindingEventsList(EventsBindingList.Add(result, bindings));
                },
                StringExtensions.FindUniqueName(bindings.Name, names), (val) =>
                {
                    val = val.Trim();

                    if (val == "")
                        return "Name cannot be empty";
                    else if (names.Any(n => n == val))
                    {
                        return "Bindings with this name already exists";
                    }
                    else
                        return null;
                });
        }

        private void deleteEventBindingsButton_Click(object sender, EventArgs e)
        {
            EventsBinding bindings =
                (eventBindingsComboBox.SelectedItem as EventsBindingItem).EventsBinding;

            EventsBindingList.Remove(bindings);
        }

        private void saveConfigsButton_Click(object sender, EventArgs e)
        {
            DefaultAmigaConfigs.SaveToXml();
        }
    }
}